<template>
  <div class="customerOverview-container">
    <div class="customerOverview-page">
      <el-card>
        <div>
           <el-button size="small" type="primary" @click="showAddLxr('add','')">新增联系人</el-button>
        </div>
        <el-table :data="list" v-loading="listLoading" border style="width: 100%; margin: 20px 0" size="small">
          <el-table-column
            label="产品线"
            align="center"
            min-width="100">
            <template slot-scope="scope">
                 {{scope.row.goodsLineName}}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="联系人"
            min-width="100">
            <template slot-scope="scope">
              {{scope.row.contactName}}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="手机号"
            min-width="150">
            <template slot-scope="scope">
              {{scope.row.contactMobile}}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="电话"
            min-width="100">
            <template slot-scope="scope">
              {{scope.row.contactPhone}}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="职务"
            min-width="100">
            <template slot-scope="scope">
              {{scope.row.contactDuty}}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="主联系人"
            min-width="100">
            <template slot-scope="scope">
              {{scope.row.isMainContact == 1 ? '是' : '否'}}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="采购决定权"
            min-width="100">
            <template slot-scope="scope">
              {{scope.row.isBuyPermission == 1 ? '有' : '没有'}}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="关注点"
            min-width="100">
            <template slot-scope="scope">
              {{scope.row.contactFocus}}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="生日"
            min-width="100">
            <template slot-scope="scope">
              {{scope.row.contactBirthday}}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="爱好"
            min-width="100">
            <template slot-scope="scope">
              {{scope.row.contactHobby}}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="状态"
            min-width="100">
            <template slot-scope="scope">
              {{scope.row.isLeaveJob == 0 ? '在职' : '离职'}}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="更新时间"
            min-width="150">
            <template slot-scope="scope">
              {{scope.row.updatedAt}}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="更新人"
            min-width="100">
            <template slot-scope="scope">
              {{scope.row.updateUserName}}
            </template>
          </el-table-column>

          <el-table-column
            fixed="right"
            align="center"
            label="操作"
            min-width="100">
            <template slot-scope="scope">
                 <el-button type="text" @click="showAddLxr('edit',scope.row)" v-if="scope.row.isCanUpdate == 1">编辑</el-button>
                 <el-button
                   @click="callMobile(scope.row)"
                   type="text"
                   size="mini">电话联系
                 </el-button>
                 <!--<el-button type="text" v-if="scope.row.isLeaveJob == 0">离职</el-button>-->
                 <el-button type="text" @click="showAddLxr('copy',scope.row)" v-if="scope.row.isCanUpdate == 1">复制</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="pagination-container">
          <el-pagination
            background
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            layout="total, sizes,prev, pager, next,jumper"
            :page-size="listQuery.pageSize"
            :page-sizes="[10,15,20]"
            :current-page.sync="listQuery.pageNum"
            :total="count">
          </el-pagination>
        </div>
      </el-card>
    </div>
    <addLxr ref="addLxr" @getList="getList"></addLxr>

  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import {formatDate} from '@/utils/date';
import store from '@/store'
import {getCustomerOption, addRelatio, delRelation,} from '@/api/partner'
import addLxr from './addLxr';
import {
  customerNewContactList,
  customerNewBaseInfo,
  callCustomerMobileAPI
} from '@/api/company'

const defaultListQuery={
  customerId:'',
  isMy:1,
  "pageNum" : 1,
  "pageSize" : 10
};
export default {
  name: "customerGoodsLine",
  data(){
    return{
      roles:store.getters.roles ? store.getters.roles : [],
      list:[],
      listQuery: JSON.parse(JSON.stringify(defaultListQuery)),
      count: 0,
      listLoading: false,
      info:{}
    }
  },
  components : {
    addLxr
  },
  computed: {
    ...mapGetters([
      'name',
      'mobile',
      'userId'
    ]),

  },
  created() {

  },
  filters: {

  },
  methods:{
     // 电话联系
    callMobile(item){
      callCustomerMobileAPI({
        contactId:item.contactId
      }).then((res)=>{
       console.log(res);
      })
    },
    init(customerId,cglId,goodsLineId){
      this.listQuery.customerId = customerId;
      if(cglId){
        this.listQuery.cglId = cglId
      }
      if(goodsLineId){
        this.listQuery.goodsLineId = goodsLineId
      }
      this.getList();
      this.getInfo()
    },
    //获取客户基本信息
    getInfo(){
      customerNewBaseInfo({customerId:this.listQuery.customerId}).then((res)=>{
        this.info = res
      })
    },
   //显示增加联系人
    showAddLxr(type,item){
      let data = {}
      if(type == 'edit'){
        data = JSON.parse(JSON.stringify(item))
      }else if(type == 'copy'){
        data = JSON.parse(JSON.stringify(item))
        data.contactId = 0;
      }
      data.customerId = this.listQuery.customerId
      data.customerName = this.info.customerName
      if(this.listQuery.goodsLineId){
        data.goodsLineId = this.listQuery.goodsLineId
      }
      this.$refs.addLxr.showContact(type,data)
    },
    handleSizeChange(val){
      this.listQuery.pageNum = 1;
      this.listQuery.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val){
      this.listQuery.pageNum = val;
      this.getList();
    },
    handleSearchList(){
      this.listQuery.pageNum = 1;
      this.getList();
    },
    //获取列表
    getList() {
      this.listLoading = true;
      customerNewContactList(this.listQuery).then(response => {
        this.list = response.list;
        this.count = response.count;
        this.listLoading = false;
      }).catch(()=>{
        this.listLoading = false;
      });
    },
  }
}
</script>

<style lang="scss">


</style>
